"""
下拉框：

selenium下拉框类
    1、创建下拉框对象

面试题：如何处理下拉框的？
    1.导入下拉框类
    2.创建下拉框对象
    3.使用下拉框对象调用他的方法
"""
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

# 创建浏览器驱动对象
driver = webdriver.Edge()
# 打开页面
driver.get("http://localhost:8081/regA.html")
# 1、创建下拉框对象   Select(放入select标签)
select=Select(driver.find_element(By.CSS_SELECTOR,"#selectA"))
print(select.options) # 获取所有选项
# select.select_by_index(0)  #从0开始的，不能使用负数
# select.select_by_value("gz")   #按照选项的value属性值进行选择
select.select_by_visible_text("广州") #按照选项的文本进行选择  文本是一个全匹配
select1=Select(driver.find_element(By.CSS_SELECTOR,"#selectA"))
select1.select_by_visible_text("深圳")
select2=Select(driver.find_element(By.CSS_SELECTOR,"#selectA"))
select2.select_by_visible_text("深圳")
Select(driver.find_element(By.CSS_SELECTOR,"#selectA")).select_by_visible_text("赣州")
time.sleep(1)
Select(driver.find_element(By.CSS_SELECTOR,"#selectA")).select_by_visible_text("赣州")
Select(driver.find_element(By.CSS_SELECTOR,"#selectA")).select_by_visible_text("赣州")
time.sleep(10)

driver.quit()